package javango.forms.fields;

import java.util.Map;

import com.google.inject.Inject;

import javango.forms.widgets.PercentInputWidget;
import javango.forms.widgets.WidgetFactory;

/**
 * Field that takes an input as a percent (ie 10) and converts it to the decimal
 * representation (ie 0.01).
 * 
 * @author john
 *
 */
public class PercentField extends DoubleField {

	@Inject
	public PercentField(WidgetFactory widgetFactory) {
		super(widgetFactory);
		setWidget(PercentInputWidget.class);
		setDecimalPlaces(0);
	}

	@Override
	public Double clean(String value, Map<String, String> errors) {
		Double d = super.clean(value, errors);
		if (d != null) {
			d = d / 100;
		}
		return d;
	}

}
